<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/17/0017
 * Time: 16:36
 */

namespace app\sports_admin\model;


use think\Model;

class SchoolLoginLog extends Model
{
    protected $pk = 'id';

    protected $table = 'school_login_log';

    public function getIpAttr($value)
    {
        return long2ip($value);
    }
    /**
     * 获取学校登录日志
     * @param $page 第几页
     * @param $rows 每页显示的条数
     * @param $sort 要排序的字段
     * @param $sortOrder 升序/降序
     * @param $searchName 要检索的字段
     * @param $start 检索的开始时间
     * @param $end 检索的结束时间
     */
    public static function getSchoolLoginLogInfo($page,$rows,$sort,$sortOrder,$searchName,$start,$end)
    {
        $result = self::where(function($query)use($searchName,$start,$end){
            if($searchName){
                $query->where('account',$searchName);
            }
            if($start && $end){
                $query->whereTime('create_time','between',["{$start}","{$end}"]);
            }
        })->order("{$sort}","{$sortOrder}")->limit($rows)->page($page)->select();
        $count = self::where(function($query)use($searchName,$start,$end){
            if($searchName){
                $query->where('account',$searchName);
            }
            if($start && $end){
                $query->whereTime('create_time','between',["{$start}","{$end}"]);
            }
        })->count();
        return  json(['rows'=>$result,'total'=>$count]);
    }
}